<?php
load_info_var($cf_controller);
load_file('notice_class',LIB_PATH);

$notice = new Notice($db);

//if($cf_admin_dpt_row)
//header("location:".SITE_ADDR.$cf_admin_dpt_row['menu_link']);
//exit;
$smarty->mypage($cf_controller,$cf_action,0) ;
//$db->setDebug(1,1);
$data = $notice->get_data_array("notice_dpt='0' AND notice_type ='0'","notice_create_time DESC",10);	//通告

//my_print($data);
//$notice_sql = "create temporary table notice_desc (notice_id int(8) NOT NULL auto_increment PRIMARY KEY,notice_dpt varchar(80) NOT NULL default '0',notice_title varchar(50) NOT NULL,notice_file varchar(40) default NULL,notice_dpt_type ENUM('0','1') NOT NULL default '0',notice_type tinyint(1) NOT NULL default '0',notice_create_time datetime NOT NULL)";
$notice_sql = "create temporary table notice_desc (select * from data_notice order by notice_create_time desc)";

$db->execute($notice_sql);
//$sql="insert into notice_desc(notice_id,notice_dpt,notice_title,notice_file,notice_dpt_type,notice_type,notice_create_time) select notice_id,notice_dpt,notice_title,notice_file,notice_dpt_type,notice_type,notice_create_time from icc_notice ORDER BY notice_create_time DESC";
//$db->execute($sql);

if($cf_admin_info['g_root'] == '0'){
	$sql_new="select * from notice_desc where notice_type !='0' group by notice_type";
	$department_data = $db->getAll($sql_new);
}else{
	$sql_new="select * from notice_desc where (notice_dpt like '%".$cf_admin_info['g_root']."%' OR notice_dpt='0') AND notice_type !='0' group by notice_type";
	$department_data = $db->getAll($sql_new);
}

//待处理事项
$row['today_order'] = $db->getOne("select count(*) as num from data_order where order_status='1' AND DATE_FORMAT(order_create_time,'%Y-%m-%d') = '".date("Y-m-d")."'");//今天订单数
$row['unpaid_order'] = $db->getOne("select count(*) as num from data_order where order_status='0'");    //未付款的订单数
$row['undelivered_order'] = $db->getOne("select count(*) as num from data_order where order_status='1'");    //待发货的订单数
$row['refund_order'] = $db->getOne("select count(*) as num from data_order where order_status='5'");    //退款中的订单数
$row['yesterday_money'] = $db->getOne("select SUM(order_all_total) as money from data_order where order_status='1' AND DATE_FORMAT(order_create_time,'%Y-%m-%d') ='".date("Y-m-d",strtotime("yesterday"))."'");//昨日成交金额

//my_print($department_data);
if($department_data){
	foreach($department_data as $k=>$v){
		if($v['notice_file']){
			$file = explode('.',$v['notice_file']);
			$department_data[$k]['thumb'] = $file[1];
		}
	}
}
//echo "xxxx";
//dump($department_data);
$drop_table = "drop table notice_desc ";
$db->execute($drop_table);

$smarty->assign(array(
    'id' => $id,
    'row' => htmlchar($row),
    'data' => $data,
	'department_data'=>$department_data,
	'g_root' => $cf_admin_info['g_root'],
    'week' => getweek(date("Y-m-d"))

));
$smarty->mydisplay();

?>